package com.iwdnb.gkgz.application.event;

import java.util.List;

import com.alibaba.fastjson.JSONObject;

import com.iwdnb.bmnf.common.eventbus.EventHandler;
import com.iwdnb.gkgz.common.model.dto.Stock;
import com.iwdnb.gkgz.common.utils.StockUtils;
import com.iwdnb.gkgz.infrastructure.dao.repo.StockRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class InitStockEventHandler implements EventHandler<JSONObject> {
    public static final String TOPIC = "initStock";
    @Autowired
    private StockRepository stockRepository;

    @Override
    public String topic() {
        return TOPIC;
    }

    @Override
    public void onMessage(JSONObject message) {
        List<Stock> stockList=stockRepository.findAll();
        StockUtils.initStock(stockList);
    }
}
